package cn.xingyun.pickaxe_loli_new.util;

import cn.xingyun.pickaxe_loli_new.item.LolipickaxeItem;
import net.minecraft.util.AbortableIterationConsumer;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.entity.*;
import net.minecraft.world.phys.AABB;

import javax.annotation.Nullable;
import java.util.UUID;
import java.util.function.Consumer;

public class MyLevelEntityGetter<T extends EntityAccess> extends LevelEntityGetterAdapter<T> {
    private final EntityLookup<T> visibleEntities;
    private final EntitySectionStorage<T> sectionStorage;
    public MyLevelEntityGetter(EntityLookup p_156943_, EntitySectionStorage p_156944_) {
        super(p_156943_, p_156944_);
        this.visibleEntities = p_156943_;
        this.sectionStorage = p_156944_;
    }
    @Nullable
    public T get(int p_156947_) {
        if (LolipickaxeItem.DarkNameList.contains(visibleEntities.getEntity(p_156947_).getClass().getName())) {
            return null;
        }
        return this.visibleEntities.getEntity(p_156947_);
    }

    @Nullable
    public T get(UUID p_156959_) {
        if (LolipickaxeItem.DarkNameList.contains(visibleEntities.getEntity(p_156959_).getClass().getName())) {
            return null;
        }
        return this.visibleEntities.getEntity(p_156959_);
    }

    public Iterable<T> getAll() {
        for (T entity : visibleEntities.getAllEntities()) {
            if (LolipickaxeItem.DarkNameList.contains(entity.getClass().getName())) {
                visibleEntities.remove(entity);
            }
        }
        return this.visibleEntities.getAllEntities();
    }

    public <U extends T> void get(EntityTypeTest<T, U> p_261718_, AbortableIterationConsumer<U> p_262009_) {
        for (T entity : visibleEntities.getAllEntities()) {
            if (LolipickaxeItem.DarkNameList.contains(entity.getClass().getName())) {
                visibleEntities.remove(entity);
            }
        }
        this.visibleEntities.getEntities(p_261718_, p_262009_);
    }

    public void get(AABB p_156956_, Consumer<T> p_156957_) {
        for (T entity : visibleEntities.getAllEntities()) {
            if (LolipickaxeItem.DarkNameList.contains(entity.getClass().getName())) {
                visibleEntities.remove(entity);
            }
        }
        this.sectionStorage.getEntities(p_156956_, AbortableIterationConsumer.forConsumer(p_156957_));
    }

    public <U extends T> void get(EntityTypeTest<T, U> p_261696_, AABB p_261693_, AbortableIterationConsumer<U> p_261719_) {
        for (T entity : visibleEntities.getAllEntities()) {
            if (LolipickaxeItem.DarkNameList.contains(entity.getClass().getName())) {
                visibleEntities.remove(entity);
            }
        }
        this.sectionStorage.getEntities(p_261696_, p_261693_, p_261719_);
    }
}
